Skip to content

Conversation

shreyas-omkar
Copy link

@shreyas-omkar shreyas-omkar commented Oct 10, 2025

Fixes #3523

Problem Description

Currently, invoking the crab1 compiler front-end without providing an input source file results in an Internal Compiler Error (ICE) due to a segmentation fault.

This occurs because a NULL pointer for the filename is passed to lang_dependent_init and subsequently to lower-level functions like init_asm_output and lrealpath, which do not handle the NULL value and lead to a crash.

Solution

This patch introduces a check inside the lang_dependent_init function in gcc/toplevel.cc. The check verifies if the input filename is nullptr. If it is, the compiler now reports a fatal_error("no input files") and terminates gracefully.

This new behavior is more robust, providing a clear error message to the user instead of an unexpected crash, and aligns better with the behavior of other GCC front-ends.

Testing

The fix was verified manually by running the compiler with no arguments and confirming that it now prints the fatal error message instead of segfaulting.

Screenshot_20251010_224635

Additionally, a full make check-rust was run successfully to ensure that no regressions were introduced by this change.


  • GCC development requires copyright assignment or the Developer's Certificate of Origin sign-off. (DCO provided via --signoff).
  • Read contributing guidelines.
  • make check-rust passes locally.
  • Run clang-format on the changed file.
  • Added any relevant test cases to gcc/testsuite/rust/. (Manual test performed to confirm fix).

@shreyas-omkar shreyas-omkar marked this pull request as ready for review October 10, 2025 17:53
@shreyas-omkar shreyas-omkar force-pushed the fix-no-input-segfault-v2 branch from 9f14789 to 801f9ac Compare October 10, 2025 19:24
@shreyas-omkar shreyas-omkar changed the title Fix: Prevent ICE on no input file gcc: Prevent ICE on no input file Oct 10, 2025
@shreyas-omkar shreyas-omkar force-pushed the fix-no-input-segfault-v2 branch 2 times, most recently from 5bd12d1 to ece8296 Compare October 11, 2025 18:17
	* toplev.cc (lang_dependent_init): Prevent ICE on no input file.

Signed-off-by: shreyas-omkar <shreyashegdeplus06@gmail.com>
@shreyas-omkar shreyas-omkar force-pushed the fix-no-input-segfault-v2 branch from ece8296 to 37210da Compare October 11, 2025 18:36
@shreyas-omkar
Copy link
Author

Heys @philberty @powerboat9 Please review and let me know any changes required.

@dkm
Copy link
Member

dkm commented Oct 13, 2025

Your commit log is not correct and must have a title (the first line), an empty line, and then a description followed by the GNU ChangeLog part.
Your commit has only the GNU ChangeLog part.

Copy link
Member

@dkm dkm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the commit log :)

Comment on lines +1915 to +1919
if (name == nullptr) {
fatal_error(input_location, "no input files");
return 0;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably breaks invocations using stdin instead of a regular file. This probably needs a different fix to use stdin in this case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will implement the invocation using stdin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: segfault when no source file is passed

2 participants